<template>
	<view>
		<view class="box">
			<view class="item">
				<text>岗位名称</text>
				<picker mode="selector" :range="postArr" range-key="postName" @change="selectPost">
					<text v-if="postName" class="info-item-right">{{postName}}</text>
					<text v-else class="info-item-right">请选择</text>
				</picker>
			</view>
			<view class="item">
				<text>岗位编号</text>
				<text class="input-style">{{postCode}}</text>
			</view>
			<!-- <view class="item">
				<text>联系电话</text>
				<input type="text" v-model="form.phonenumber" placeholder="请输入" class="input-style" />
			</view> -->
		</view>
		<view class="box">
			<view class="item">
				<text>紧急联系人</text>
				<input type="text" v-model="form.emergencyName" placeholder="请输入" class="input-style" />
			</view>
			<view class="item">
				<text>紧急联系电话</text>
				<input type="text" v-model="form.emergencyTel" placeholder="请输入" class="input-style" />
			</view>
		</view>
		<view class="box">
			<view class="item">
				<text>教育背景</text>
				<picker mode="selector" :range="educateArr" range-key="name" @change="selectEducate">
					<text v-if="education" class="info-item-right">{{education}}</text>
					<text v-else class="info-item-right">请选择</text>
				</picker>
			</view>
			<view class="item">
				<text>专业</text>
				<input type="text" v-model="form.major" placeholder="请输入" class="input-style" />
			</view>
			<view class="item">
				<text>入职日期</text>
				<picker mode="date" @change="selectWorkTime">
					<text v-if="workTime" class="info-item-right">{{workTime}}</text>
					<text v-else class="info-item-right">请选择</text>
				</picker>
			</view>
			<view class="item">
				<text>介绍人</text>
				<input type="text" v-model="form.introducer" placeholder="请输入" class="input-style" />
			</view>
			<view class="item">
				<text>原从事单位</text>
				<input type="text" v-model="form.lastJob" placeholder="请输入" class="input-style" />
			</view>
			<view class="sex-box">
				<text>是否有诉讼记录</text>
				<radio-group class="sex-item" @change="radioChange">
					<label>
						<view class="radio-box">
							<radio :checked="form.law==1" value="1" /><text class="sextext">有</text>
						</view>
					</label>
					<label>
						<view class="radio-box">
							<radio :checked="form.law==0" value="0" /><text class="sextext">无</text>
						</view>
					</label>
				</radio-group>
			</view>
		</view>
		<view class="bottom">
			<view class="bottom-box">
				<view class="bottom-radio">
					<checkbox-group @change="checkCommitted">
						<checkbox value="1" :checked="committed==1" /><text class="bottom-radio-text">承诺为真实信息，如有虚假自愿承担公司及法律责任</text>
					</checkbox-group>
				</view>
				<view class="submit" @click="submit">提交信息</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{},
				postArr:[], //岗位名称
				educateArr:[{name:'博士'},{name:'硕士'},{name:'全日制本科'},{name:'本科'},{name:'专科'},{name:'其他'}],//教育背景
				professionArr:[] ,//专业
				postCode:"",
				postName:"",
				education:'',
				workTime:"",
				law:"0",
				committed:'1',
				committedStatus:true
			}
		},
		onShow() {
			this.form = uni.getStorageSync('regForm')
			this.getPost()
			if(!this.form.law) {
				this.form.law = '0'
			}
		},
		methods: {
			getPost() {
				this.$utils.http.get('system/postList',{}).then((res)=>{
					if(res.code == 200) {
						this.postArr = res.data
					}
				})
			},
			// 选择岗位
			selectPost(e) {
				this.form.postName = this.postArr[e.detail.value].postName
				this.postName = this.postArr[e.detail.value].postName
				this.form.postCode = this.postArr[e.detail.value].postCode
				this.postCode = this.postArr[e.detail.value].postCode
				this.form.postIds = [this.postArr[e.detail.value].postId]
				uni.setStorageSync('regForm',this.form)
			},
			// 选择教育背景
			selectEducate(e){
				this.form.education = this.educateArr[e.detail.value].name
				this.education = this.educateArr[e.detail.value].name
				uni.setStorageSync('regForm',this.form)
			},
			// 入职日期
			selectWorkTime(e) {
				this.form.workTime = e.detail.value
				this.workTime = e.detail.value
				uni.setStorageSync('regForm',this.form)
			},
			// 是否有诉讼记录
			radioChange(e) {
				this.form.law = e.detail.value
				uni.setStorageSync('regForm',this.form)
			},
			// 是否勾选承诺
			checkCommitted(e) {
				if(e.detail.value.length>0) {
					this.committedStatus = true
				}else {
					this.committedStatus = false
				}
			},
			// 提交
			submit() {
				if(this.committedStatus) {
					console.log(this.form)
					this.submitPost()
				}else {
					uni.showToast({
						title:'请承诺您所填信息为真实信息',
						icon:'none'
					})
				}
			},
			// 提交接口
			submitPost() {
				uni.showLoading({
					title:'注册中',
					mask:true
				})
				var that = this
				this.$utils.http.post('/mobileUser/register/'+this.form.smscode, this.form)
					.then(res => {
						console.log(JSON.stringify(res));
						if (res.code === 200) {							
							uni.showToast({
								icon: 'none',
								position: 'bottom',
								title: '注册成功！'
							});
							uni.clearStorageSync('regForm')
							setTimeout(function(){
								that.$utils.navto('/pages/login/login')
							},2000);
						} else {
							uni.showToast({
								icon: 'none',
								position: 'bottom',
								title: res.msg
							});
						}
					})
					.catch(err => {
						console.log("register for error");
						uni.showToast({
							icon: 'none',
							position: 'bottom',
							title: '注册失败！'
						});
					})
			}
		}
	}
</script>
<style>
	page {
		background-color: #F8F9FC;
	}
</style>
<style scoped>
	.box {
		width: 100%;
		background-color: #FFFFFF;
		margin: 20upx 0upx;
		font-size: 28upx;
		padding: 0upx 30upx;
		box-sizing: border-box;
	}
	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20upx 0upx;
		box-sizing: border-box;
		width: 100%;
		border-bottom: 1px solid #EAEAEA;
	}
	.info-item-right::after {
		content: '\e60d';;
		margin-left: 10upx;
		color: #A2A2A2;
		font-size: 14px;
		font-family: iconfont;
	}
	.input-style {
		flex-grow: 1;
		margin-left: 60upx;
		text-align: left;
	}
	.sex-box {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #EAEAEA;
		padding: 30upx 0upx;
	}
	.sex-item {
		flex-grow: 1;
		margin-left: 100upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.radio-box {
		display: flex;
		align-items: center;
	}
	.sextext {
		margin-left: 60upx;
	}
	.bottom {
		width: 100%;
		background-color: #FFFFFF;
		position: absolute;
		bottom: 0upx;
		left: 0upx;
		padding: 30upx 0upx;
		box-sizing: border-box;
	}
	.bottom-box {
		width: 92%;
		margin: 0upx auto;
	}
	.bottom-radio {
		display: flex;
		align-items: center;
	}
	.bottom-radio-text {
		color: #8b8b8b;
		font-size: 24upx;
	}
	.submit {
		width: 100%;
		color: #FFFFFF;
		background-color: #2962F9;
		padding: 20upx 0upx;
		text-align: center;
		border-radius: 10upx;
		margin-top: 30upx;
		font-size: 28upx;
	}
</style>
